<template>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span>短信统计</span>
        <span class="headerSize">已发送短信： {{ pageData.total }} 条</span>
      </div>
    </template>
    <el-form
      ref="ruleFormRef"
      inline
      label-width="120px"
      class="demo-ruleForm"
      status-icon
    >
      <el-form-item>
        <el-input
          style="width: 300px"
          v-model="pageData.mobile"
          placeholder="请输入标识/手机号"
          clearable
          @clear="getUserSmsLog"
        >
          <template #append>
            <el-button class="curr" type="primary" @click="getUserSmsLog"
              >搜索</el-button
            >
          </template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-select
          v-model="pageData.timeType"
          placeholder="发送时间"
          @change="getUserSmsLog"
          clearable
        >
          <el-option label="今天" value="1" />
          <el-option label="昨天" value="2" />
          <el-option label="本周" value="3" />
          <el-option label="本月" value="4" />
        </el-select>
      </el-form-item>
    </el-form>
    <el-table
      :data="smsListArr"
      style="width: 100%"
      class="margintop"
      v-loading="isLoading"
      :header-cell-style="{ 'border-bottom': 'none' }"
      :header-row-style="{ height: '60px' }"
      :cell-style="{ height: '60px', 'border-bottom': 'none' }"
      stripe
    >
      <el-table-column prop="mobile" label="对象" width="200" />
      <el-table-column prop="smsTypeName" label="类型" width="200" />
      <el-table-column prop="content" label="短信内容" />
      <el-table-column prop="creationTime" label="发送时间" width="200" />
    </el-table>
    <div class="right" style="margin-top: 20px">
      <el-config-provider :locale="zhCn">
        <el-pagination
          v-model:current-page="pageData.page"
          v-model:page-size="pageData.pageSize"
          :page-sizes="[10, 20, 30]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageData.total"
          @size-change="getUserSmsLog"
          @current-change="getUserSmsLog"
        />
      </el-config-provider>
    </div>
  </el-card>
</template>
<script setup>
import { ref, reactive } from 'vue';
import { userSmsLog } from '@/api/manage/manage.js';
import zhCn from 'element-plus/es/locale/lang/zh-cn';

const pageData = reactive({
  page: 1,
  pageSize: 10,
  total: 0,
});

const isLoading = ref(false); // 是否正在加载
const smsListArr = ref([]); // 短信列表数组

getUserSmsLog();
// 获取短信列表
function getUserSmsLog() {
  Object.keys(pageData).forEach(function (key) {
    if (pageData[key] === '') {
      delete pageData[key];
    }
  });

  isLoading.value = true;
  userSmsLog(pageData)
    .then((res) => {
      isLoading.value = false;
      smsListArr.value = res.data.data;
      pageData.total = res.data.total;
    })
    .catch(() => {
      isLoading.value = false;
    });
}
</script>
<style lang="scss" scoped>
::v-deep(.el-form--inline .el-form-item) {
  margin-right: 7px;
}

::v-deep(.el-form-item--default) {
  margin-bottom: 4px;
}

.box-card {
  margin: 20px;

  .card-header {
    font-size: 20px;
    font-weight: 600;
    color: #1d2129;
    padding: 10px;

    .headerSize {
      color: #4e5969;
      font-size: 14px;
      margin-left: 12px;
      font-weight: 400;
      height: 20px;
      line-height: 21px;
    }
  }
}
</style>
